package com.gjy.sql.oracle.newland;

import com.gjy.sql.oracle.OracleUtil;
import org.junit.Test;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-02-27 10:10:54
 */
public class OTest {

    @Test
    public void test12() {
        String sql = "select * from SERVICE_RECORD_DETAILS_120_INFORMATION_ENTERPRISE_CHANNEL where EXTRA_DATA_ID='2023031024401'";
        Connection connection = OracleUtil.connection();
        try {
            PreparedStatement ps = connection.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                String r1 = rs.getString("SETTLE_PROPORTION");
                BigDecimal r2 = rs.getBigDecimal("SETTLE_PROPORTION");
                double r3 = rs.getDouble("SETTLE_PROPORTION");
                System.out.println("r1 = " + r1);
                System.out.println("r2 = " + r2);
                System.out.println("r3 = " + r3);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void test11() {
        String sql="insert into test_11 (a, b) values (?,?)";
        Connection connection = OracleUtil.connection();
        try {
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setObject(1,0.0);
            ps.setObject(2,0.0);
            ps.executeUpdate();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void test8() throws Exception {
        String sql = "select * from SERVICE_RECORD_SOURCE_DETAILS_120 where ORIGINAL_UUID='21D82E5091A7B71BE063AF2DB40AC03D'";
        Connection connection = OracleUtil.connection();
        PreparedStatement ps = connection.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        ResultSetMetaData metaData = rs.getMetaData();
        int columnCount = metaData.getColumnCount();

        if (rs.next()) {
            for (int i = 1; i <= columnCount; i++) {
                String columnName = metaData.getColumnName(i);
                Object value = rs.getObject(i);
                System.out.println(columnName + ":" + value + ":" + metaData.getColumnTypeName(i));
            }
        }
    }

    @Test
    public void test1() throws Exception {
        String sql = "SELECT COUNT(DISTINCT TASK_ID) C FROM CFG_SETTLE_COLLECT_TASK_APPROVE";
        Connection connection = OracleUtil.connection();
        PreparedStatement ps = connection.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();

        if (rs.next()) {
            Object tbsj = rs.getObject("C");
            System.out.println(tbsj);
        }
    }

}
